package com.bw.aop;


import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class Myaop {


    @Around("execution( * com.bw.controller.*.*(..)       )")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {

        String name = joinPoint.getSignature().getName();
        System.out.println("方法名" + name);
        Object[] args = joinPoint.getArgs();

        System.out.println("入参 " + JSONUtil.toJsonStr(args)); // 入参使用JSON格式打印   JSON  hutool出品

        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();  // 执行原方法
        long l2 = System.currentTimeMillis();
        System.out.println("方法返回值 " + proceed);

        System.out.println("方法执行时间为" + (l2 - l));

        return proceed;
    }
}
